<template>
	<view>
    <!-- 搜索组件 -->
    <view class="search-box">
        <my-search></my-search>
    </view>
		<!-- 轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true" class="swiper">
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=` + item.goods_id"  class="swiper-item">
          <image :src="item.image_src" mode="widthFix"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 分类导航 -->
    <view class="nav-list">
      <view v-for="(item,index) in navList" :key="index" @click="handleItemClick(item)">
        <image :src="item.image_src"></image>
      </view>
    </view>
    
    <!-- 楼层展示 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,index) in floorList" :key="index">
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        <!-- 楼层图片区域 -->
        <view class="floor-image-box">
          <navigator class="floor-left" :url="item.product_list[0].url">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
          </navigator>
         <view class="floor-right">
            <navigator class="right-img" v-for="(item,index) in item.product_list" :key="index" v-if="index !== 0" :url="item.url">
              <image :src="item.image_src" mode="widthFix" :style="{width: item.image_width + 'rpx'}"
              ></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
	</view>
</template>

<script>
  import {SwiperListData,NavListData,FloorListData} from '../../service/home_api.js'
  import mySearch from '../../components/my-search.vue'
  import badgeMix from '../../mixins/tabbar-badge.js'
	export default {
    mixins:[badgeMix],
    components:{
      mySearch
    },
		data() {
			return {
				swiperList:[],
        navList:[],
        floorList:[]
			};
		},
		onLoad:function(){
			this.getPageData()
		},
			
		methods:{
      //获取页面所有数据
      getPageData(){
        this.getSwiperList()
        this.getNavList()
        this.getContentList()
      },
      //1.获取轮播图数据
			async getSwiperList(){
        const res = await SwiperListData()
        this.swiperList = res.message
			},
      //2.获取分类导航
      async getNavList(){
        const res = await NavListData()
        this.navList = res.message
      },
      //3.获取楼层数据
      async getContentList(){
        const res = await FloorListData()
        //对数据进行处理
        res.message.forEach( floor =>{
          floor.product_list.forEach(prod => {
            //挂载自定义属性路径
            prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
          })
        })
        this.floorList = res.message
        console.log(res.message)
      },
      //nav-item点击事件
      handleItemClick(item){
        console.log(item.name)
        if(item.name === "分类"){
          uni.switchTab({
            url:"/pages/cate/cate"
          })
        }
      }
		},
    

    

	}
</script>

<style lang="scss">
  .search-box{
    position:sticky;
    top:0;
    z-index:999;
  }
.swiper{
  height:330rpx;
  
  .swiper-item,image{
    width:100%;
    height:100%;
  }
  
}

.nav-list{
  display: flex;
  justify-content: space-around;
  margin:20rpx 0;
  
  image{
    width:128rpx;
    height:140rpx;
  }
}

.floor-title{
  height:60rpx;
  width:100%;
}
.floor-right{
  display: flex;
  justify-content: space-around;
flex-wrap: wrap;
}
.floor-image-box{
  display: flex;
  padding-left: 10rpx;
}
</style>
